define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vip/caijin/index' + location.search,
                    add_url: 'vip/caijin/add',
                    edit_url: 'vip/caijin/edit',
                    del_url: 'vip/caijin/del',
                    multi_url: 'vip/caijin/multi',
                    table: 'vip_caijin',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {
                            field: 'save_money', title: __('Save_money'), operate:'BETWEEN',
                            formatter: function(value){
                                if(value % 100000000 == 0){
                                    return value / 100000000 + "亿";
                                } else if(value % 10000 == 0){
                                    return value / 10000 + "万";
                                }
                            }
                        },
                        {
                            field: 'level_start', title: 'VPI等级要求',
                            formatter: function(value,row){
                                if(value == row.level_end){
                                    return "VIP " + value;
                                } else {
                                    return "VIP " + value + "-" + row.level_end;
                                }
                            }
                        },
                        {field: 'level_start', title: __('Level_start'),visible: false},
                        {field: 'level_end', title: __('Level_end'),visible: false},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});